package com.baidu.health.service;

import com.baidu.health.pojo.resVo.resFaqListVo;
import com.baidu.health.pojo.resVo.resFaqVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baidu.health.pojo.TbFeedback;
import com.baidu.health.mapper.TbFeedbackMapper;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class TbFeedbackServiceImpl extends ServiceImpl<TbFeedbackMapper, TbFeedback>{

    @Autowired
    TbFeedbackMapper feedbackMapper;

    @Autowired
    RabbitTemplate rabbitTemplate;

    public resFaqVo userFeedback(TbFeedback feedback) {
        feedbackMapper.insert(feedback);
        rabbitTemplate.convertAndSend("userFeedbackExchanges","userFeedback",feedback);
        return new resFaqVo(200,"反馈正在处理",null);
    }

    public resFaqListVo getFeedbackList(Integer pageNum, Integer pageSize) {
//        Page<TbFeedback> feedbackPage = new Page<>(pageNum,pageSize);
//        Page<TbFeedback> tbFeedbackPage = feedbackMapper.selectPage(feedbackPage, null);
        List<TbFeedback> list = feedbackMapper.getFeedbackList(pageNum,pageSize);
        int size = feedbackMapper.selectList(null).size();
        return new resFaqListVo(200,"查询成功",list,size);
    }

    public resFaqVo changesFeedbackStatus(TbFeedback feedback) {
        feedback.setFeedbackStatus(1);
        feedbackMapper.updateById(feedback);
        // TODO:可以添加用户通知

        return new resFaqVo(200,"更新成功",null);
    }
}




